package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lupengning
 * @version 1.0
 * @description:
 * @date 2021/6/15 19:33
 */
@Slf4j
@RestController
@Api(tags = "借款人管理")
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

  @Resource
  private BorrowerService borrowerService;

  @ApiOperation("获取借款人信息列表")
  @GetMapping("/list/{page}/{limit}")
  public R listPage(
      @PathVariable @ApiParam(value = "当前页码", required = true) Long page,
      @PathVariable @ApiParam(value = "每页记录数", required = true) Long limit,
      @ApiParam(value = "查询关键字", required = false) @RequestParam String keyword) {

    Page<Borrower> borrowerPage = new Page<>(page, limit);
    IPage<Borrower> pageModel = borrowerService.listPage(borrowerPage, keyword);
    return R.ok().data("pageModel", pageModel);
  }


  @ApiOperation("获取借款人详细信息")
  @GetMapping("/show/{id}")
  public R show(@ApiParam(value = "借款人Id", required = true) @PathVariable Long id) {
    BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVOById(id);
    return R.ok().data("borrowerDetailVO", borrowerDetailVO);
  }

  @ApiOperation("借款额度审批")
  @PostMapping("/approval")
  public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {

    borrowerService.approval(borrowerApprovalVO);
    return R.ok().message("审批完成");
  }

}
